package com.myzhang;

import com.myzhang.interfacee.PersonDao;
import com.myzhang.javabean.Person;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import org.junit.Test;

public class test {
    @Test
    public void test() throws IOException {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory =
                new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        PersonDao mapper = sqlSession.getMapper(PersonDao.class);
        //Person person = mapper.getPerson(1);
        //int updatePerson = mapper.updatePerson(new Person(1, "李四", "男", 21));
        int deletePerson = mapper.deletePerson(2);
        sqlSession.commit();
        System.out.println(deletePerson);
    }
}
